#ifndef __MAIZE_RTOS_H
#define __MAIZE_RTOS_H

#include "mzdef.h"
#include "mzconfig.h"
#include "mzlist.h"

#ifdef __cplusplus
extern "C" {
#endif

/* Lib */
void mz_strcpy(char* dst, const char* src);

/* Object */
void mz_object_init(mz_object_t object,
                    const char* name,
                    mz_uint8_t type);
void mz_object_system_init(void);
void mz_object_debug(mz_object_type_t type);

/* Timer */
void mz_timer_init(mz_timer_t timer,
                   const char* name,
                   void (*entry)(void* arg),
                   void* arg,
                   mz_tick_t cycle,
                   mz_int32_t repeat);
void mz_timer_start(mz_timer_t timer);
void mz_timer_stop(mz_timer_t timer);
void mz_timer_system_init(void);
void mz_timer_check(void);
void mz_timer_debug_sort(void);

/* Clock */
mz_tick_t mz_tick_get(void);
void mz_tick_beat(void);

/* Thread */
void mz_thread_init(mz_thread_t thread,
                    const char* name,
                    void (*entry)(void* arg),
                    void* arg,
                    void* stack_addr,
                    mz_uint32_t stack_size,
                    mz_uint8_t priority,
                    mz_tick_t tick);
mz_thread_t mz_thread_self(void);
void mz_thread_delay(mz_tick_t tick);
void mz_thread_yield(void);

/* Scheduler */
void mz_schedule(void);
void mz_scheduler_start(void);
void mz_scheduler_insert_thread(mz_thread_t thread);
void mz_scheduler_remove_thread(mz_thread_t thread);
void mz_scheduler_system_init(void);

/* Idle */
void mz_idle_init(void);

/* IPC */
#if MZ_USE_MUTEX
void mz_mutex_init(mz_mutex_t mutex,
                   const char* name,
                   mz_uint8_t flag);
void mz_mutex_take(mz_mutex_t mutex);
void mz_mutex_release(mz_mutex_t mutex);
#endif

mz_inline void mz_init(void){
    mz_object_system_init();
    mz_timer_system_init();
    mz_scheduler_system_init();
    mz_idle_init();
}

#ifdef __cplusplus
}
#endif

#endif